/**============================================================================
 *
 * Author: luo1o1o1o 
 *
 * Last modified: 2021-07-23 14:59
 *
 * Description: 首页 API 路由
 *
 ============================================================================**/

const router = require('koa-router')()
const { loginChecks } = require('../../middlewares/loginChecks')
const { create } = require('../../controller/blog-home')
const { genValidator } = require('../../middlewares/validator')
const blogValidate = require('../../validator/blog')

router.prefix('/api/blog')

// 创建微博
router.post(
    '/create',
    loginChecks,
    genValidator(blogValidate),
    async (ctx, next) => {
        const { content, image } = ctx.request.body
        const { id: userId } = ctx.session.userInfo
        // controller
        ctx.body = await create({ userId, content, image })
    }
)

module.exports = router
